package com.stone;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
/**
 * 该类中主要的工作由AnimateDrawable完成。在该类间接继承了Drawable.
 * android.view.animation包中的Animation类表示一个动画效果。其有几个子类
 * TranslateAnimation--位置动画
 * RotateAnimation--旋转动画
 * ScaleAnimation--缩放动画
 * AlphaAnimation--透明动画
 * AnimationSet--动画组
 * */
public class AnimateDrawables extends Activity {
   @Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(new MyView(this));
}
    private static class MyView extends View{
       private AnimateDrawable mDrawable;
		public MyView(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
		    setFocusable(true);
		    setFocusableInTouchMode(true);
		    Drawable dr=getResources().getDrawable(R.drawable.beach);
		    dr.setBounds(0,0,dr.getIntrinsicWidth(),dr.getIntrinsicHeight());
		    Animation an=new TranslateAnimation(0,100,0, 200);
		    an.setDuration(2000);
		    an.setRepeatCount(-1);
		    an.initialize(10, 10,10,10);
		    mDrawable=new AnimateDrawable(dr,an);
		    an.startNow();
		}
    	@Override
    		protected void onDraw(Canvas canvas) {
    			// TODO Auto-generated method stub
    			super.onDraw(canvas);
    			canvas.drawColor(Color.WHITE);
    			mDrawable.draw(canvas);
    			invalidate();
    		}
    }
}
